<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>each循环</title>
    </head>
    <body>
    </body>
    <script>
    function isArrayLike(obj){
    	if(Object.prototype.toString.call(obj)== '[object Array]'){
    		return false;
    	}
    	var length ='length' in obj &&obj.length;
    	return typeof length === 'number'&& length >=0;

    }
    function each(arr, callback ){
    	if(isArrayLike (arr) ){
    		for(var i=0;i<arr.length;i++){
    			if( callback.call( arr[i], arr[i], i) === false ) break;
    		}
    	}else{
    		for(var k in arr){
    			if(callback.call(arr[k],arr[k],k)=== false ) break;
    		}
    	}
    	return arr;
    }




var o={
	name:'jim',
	age:19,
	gender:'男'
};

each (o,function(v,i){
	console.log(this);
	console.log(i+','+v);
})




    </script>
</html>